#!/bin/bash

#########################################################################
#                                                                       #
# Nombre: torrent_taging_beta.sh                                        #
# Version: 0.1b                                                         #
# Author: A.Ruiz                                                        #
# Desc: Asigna un tag especifico a un torrent en descarga               #
#                                                                       #
#########################################################################

LOG_FILE='/aplicaciones/logs-server/torrent_taging.log'
LOG_EJE=`date +%d/%m/%Y %H:%M`

# GENERAMOS FICHERO LOG SI ES NECESARIO
if [ ! -f $LOG_FILE ]; then
	touch $LOG_FILE
fi

echo "INIT - torrent_taging_beta.sh - () " >> $LOG_FILE

# COMPROBAMOS PARAMETROS
if [ $# < 2 ]; then
	echo "INCORRECT NUMBER OF PARAMS -- $#" >> $LOG_FILE
	echo "END WITH ERROR - torrent_taging_beta.sh - " >> $LOG_FILE
	exit 1
else
	TORRENT_HASH=$1
	TORRENT_TAG=$2
fi

# REALIZAMOS UPDATE
sql-plus ...
if [ $? -eq 0 ]; then
	echo "TORRENT TAGGED: $TORRENT_HASH - $TORRENT_TAG" >> $LOG_FILE
	echo "END WITHOUT ERROR - torrent_taging_beta.sh - " >> $LOG_FILE
	exit 0
else
	echo "CANNOT TAG TORRENT: $TORRENT_HASH - $TORRENT_TAG" >> $LOG_FILE
	echo "END WITH ERROR - torrent_taging_beta.sh - " >> $LOG_FILE
	exit 2
fi

